/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.windesheim.archdemo.presentationmodel;

import nl.windesheim.archdemo.dao.CustomerDao;
import nl.windesheim.archdemo.dao.GlobalInstances;
import nl.windesheim.archdemo.model.Address;
import nl.windesheim.archdemo.model.Customer;
import nl.windesheim.archdemo.view.CustomerPanel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

/**
 *
 * @author re0053273
 */
public class CustomerPanelPresenter {

    private CustomerDao customerDao = GlobalInstances.getCustomerDao();
    private Customer customer;
    private CustomerPanel view;

    public void setCustomer(Customer c) {
        this.customer = c;
        view.getAdres().setText(getAddress());
        view.getNaam().setText(customer.getName());
        view.getOrderCount().setText(getOrderCount());
    }
    
    public CustomerPanelPresenter(CustomerPanel view){
        this.view = view;
    }
    
    public Customer getCustomer(){
        return this.customer;
    }

    private String getAddress() {
        Address a = customer.getAddress();
        return String.format("%s %s %s, %s %s", a.getPostcode(), a.getHouseNumber(), a.getNumberExtension(),
                a.getCity(), a.getCountry());
    }

    private String getOrderCount() {
        return customerDao.getOrderCount(customer).toString();
    }
}
